Repository navigation
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
PR commands & links...
|
|
Fix for |
colemanw
left a comment
There was a problem hiding this comment.
@ufundo I tested this out and aside from some minor nits (comments inline) the one major issue is that CRM_Upgrade_DispatchPolicy::pick() now picks 'upgrade.finish' instead of 'upgrade.main' while the core upgrade task was still running.
That's because CRM_Core_BAO_Domain::isDBUpdateRequired() still compares civicrm_domain.version against CRM_Utils_System::version()
| $maxRevision = empty($revisions) ? NULL : end($revisions); | ||
| reset($revisions); | ||
| if (version_compare($latestVer, $maxRevision, '<')) { | ||
| throw new CRM_Core_Exception("Malformed upgrade sequence. The incremental update $maxRevision exceeds target version $latestVer"); |
There was a problem hiding this comment.
The trouble with removing this is that if would have caught typos in upgrade method/sql.tpl names.
I would suggest only skipping the exception if the version string ends in .alpha\d so it works on CI but only for pre-release versions... but that doesn't actually solve #38063 since it's 6.20.1 🤔
There was a problem hiding this comment.
Yeh, I don't think checking alpha works.
if would have caught typos in upgrade method/sql.tpl names.
What sort of typo? At any rate to me that feels like a check that should happen at release time (maybe as part of set-version.php) rather than at runtime
There was a problem hiding this comment.
I've added a sanity check to set-version.php now
Hmm yes good catch |
737d38d to
f030eb3
Compare
That was thornier than I had anticipated. I've refactored out a bit of the Versions stuff from |
f030eb3 to
2dbb9cb
Compare
|
@totten did you see this ping? |
civireview
left a comment
There was a problem hiding this comment.
CiviReview: 🟡 Questions only · 4/5
Lets the upgrader run incremental steps declared beyond the xml/version.xml version (pre-release). It moves version logic into a new CRM_Upgrade_Versions class and adds a set-version.php guard.
To address (3)
- LOW
CRM/Upgrade/Versions.php:95-104— validateUpgradeVersions(string $currentVer) turns the 'Version information missing' error into a TypeError - LOW
tools/bin/scripts/set-version.php:47-50— set-version.php upgrade-step guard silently passes ifcvis missing or fails - LOW
CRM/Upgrade/DispatchPolicy.php:50— Other 'upgrade pending' checks still compare the DB version to the XML version only
✅ CI · ✅ Base tests · ✅ Surface · ✅ Threads
Verification (4 checks, 2 not verified)
Score (4/5): 3 low-severity or question-only finding(s).
PR: civicrm/civicrm-core#38139 · Profile: core · Kind: core-feature · Commits: 4d8d01d → 2dbb9cb
| Check | Status | Detail |
|---|---|---|
| CI / Jenkins | ✅ PASS | 1 CI checks: 1 passed, 0 failed, 0 pending. |
| Base-Test Regression | ✅ PASS | PR merged into eb5f766: 10 test(s) passed on A and B |
| Live Surface Diff | ✅ PASS | Live APIv4/APIv3/routes/Afform surface diff captured with 0 risk flags. |
| Reviewer Thread | ✅ PASS | All 6 reviewer question/request(s) addressed or answered. |
Not verified:
- upgrade path (CRM/Upgrade/*) not verified locally
- No added/modified PHPUnit tests in PR; Proof-of-Fix A/B test skipped.
Outside this review: any CMS other than Standalone; viewports other than 1280×800; whether the approach is right for the project; whether and when to merge. The verdict and the score speak of what was checked: they prepare a human review and do not replace it.
Reviewer threads (all 6 addressed/answered)
| Reviewer | Question / Request | Status | Detail |
|---|---|---|---|
colemanw |
ts() named placeholders in the General.php pre-upgrade message | ✅ Addressed | General.php now uses %1/%2 numbered placeholders. |
colemanw |
NULL $maxRevision passed to version_compare | ✅ Addressed | Versions::getLatestVersion() line 77 now guards with $maxRevision &&. |
colemanw |
Removing the Malformed upgrade sequence check loses typo protection | 💬 Answered | The author moved the check to set-version.php at release time. That check silently passes if cv fails (see the set-version fail-open finding). |
colemanw |
DispatchPolicy::pick() selecting upgrade.finish while the core upgrade is still running | ✅ Addressed | pick() now uses CRM_Upgrade_Versions::upgradesPending(), which compares against the latest declared step. |
colemanw |
set-version.php now depends on an installed Civi DB / bare-checkout releaser | 💬 Answered | The author says only classloader level is needed. It was not verified that cv works in the bare-checkout releaser, and the guard silently passes if it does not. |
seamuslee001 |
latest.civicrm.org release system does not install a DB | 💬 Answered | The author replied that only classloading is required, via cv ev --level=classloader. Whether cv is available there is unconfirmed. |
More: Walkthrough · standards (3 issues) · blast radius · lower-confidence notes (1) · rejected (2)
Walkthrough
- CONFIRMED: The new class CRM_Upgrade_Versions computes getLatestVersion() as max(XML version, highest declared step). CRM_Upgrade_Form delegates to it, and the 'Malformed upgrade sequence' throw is removed from buildQueue(). The author moved that protection to set-version.php in response to
colemanw. - CONFIRMED: DispatchPolicy::pick() now uses Versions::upgradesPending(), which addresses the upgrade.finish-mid-upgrade problem
colemanwfound. No PHPUnit test covers it. - PROVEN: validateUpgradeVersions() has non-nullable string parameters, so a NULL domain version gives a TypeError instead of the 'Version information missing' CRM_Core_Exception (reproduced on stack B).
- PROVEN: The set-version.php check uses exec('cv ev ...') without checking the result. If cv fails, exec returns '' and the check silently passes.
- CONFIRMED: isDBUpdateRequired() (used by the status checks and civiimport) and EntityProvider::getSupportedFields() still compare against the XML version only. This only affects dev sites with pre-release steps.
- NOT VERIFIED: A full pre-release upgrade run, because no step above the XML version exists in the stacks, and set-version.php in the actual releaser environment.
CiviCRM core standards
| Code | Status | Note |
|---|---|---|
r-explain |
PASS | The PR body explains the goal. The new pre-upgrade message warns users about pre-release steps. |
r-user |
PASS | This only affects dev sites that have pre-release steps. Released code is unaffected. Remaining status-check gap: see 'Other upgrade pending checks' (low). |
r-doc |
N/A | Developer-only behaviour. A dev-docs note would be nice but is not required. |
r-run |
ISSUE | No pre-release scenario (a step above the XML version) was run through the web or CLI upgrader. Only the existing tests ran. |
r-tech |
PASS | The CRM_Upgrade_Form wrapper methods keep their signatures and return shapes. |
r-code |
ISSUE | See the validateUpgradeVersions TypeError finding and the set-version.php fail-open guard finding. |
r-maint |
ISSUE | See 'No tests for CRM_Upgrade_Versions'. |
r-test |
PASS | CI is green and A/B shows no regressions in the existing upgrade tests. |
rg-upgrades |
PASS | No new upgrade steps. The new release-time guard in set-version.php can be silently skipped (see the set-version fail-open finding). |
Ecosystem blast radius
| Repo | Path | Symbol | Impact |
|---|---|---|---|
| civicrm-core | CRM/Upgrade/Page/Upgrade.php |
CRM_Upgrade_Form::getUpgradeVersions |
The web upgrader now targets max(XML version, highest step) and is affected by the NULL-version TypeError finding. |
| civicrm-core | CRM/Upgrade/Headless.php |
CRM_Upgrade_Form::getUpgradeVersions |
The CLI/headless upgrade has the same target-version change and the same TypeError path. |
| civicrm-core | CRM/Upgrade/DispatchPolicy.php |
CRM_Upgrade_DispatchPolicy::pick |
In upgrade mode it now calls upgradesPending(), which scans the incremental classes to find the max revision. |
| civicrm-core | CRM/Core/BAO/Domain.php |
isDBUpdateRequired |
Still compares against the XML version, so the Env/Schema checks and civiimport disagree with the upgrader when pre-release steps are pending. |
| civicrm-core | Civi/Schema/EntityProvider.php |
getSupportedFields |
Filters pending fields against the XML version, not the latest declared step. |
| civicrm-core | tools/bin/scripts/set-version.php |
set-version guard |
Release tooling now shells out to cv. The guard silently passes if cv is unavailable. |
Lower-confidence notes (below the posting gate)
- [LOW | NEEDS_QUESTION | 55%]
CRM/Upgrade/Form.php:512-513— Removing the 'Malformed upgrade sequence' guard lets a mistyped upgrade step silently become the DB target version: The runtime check in buildQueue() that rejected a revision above the target version is removed. getLatestVersion() now adopts any higher revision as the target.
Rejected or below 50% confidence
- [LOW | REJECTED | 20%]
CRM/Upgrade/Versions.php:95-104— validateUpgradeVersions(string, string) turns the 'Version information missing' exceptions into a TypeError — verifier: Same defect, same lines as corr-1, which is PROVEN. Rejected only to avoid duplication. - [LOW | REJECTED | 20%]
tools/bin/scripts/set-version.php:47-50— set-version.php guard is silently skipped ifcvfails, and the removed runtime guard was never replaced by a test — verifier: The fail-open mechanism is PROVEN under corr-3. The CI-test suggestion overlaps corr-2 and tests-no-coverage-versions. Rejected as a duplicate.
1 further candidate finding(s) are not listed: duplicates of the findings above, or lower-confidence notes beyond the five shown.
Automated AI-assisted review, alpha: it may miss issues or report false positives, so verify findings before acting and open an issue with feedback. Reviewed by civireview · sonnet-opus · 1,535,483 tokens · $1.07
| public static function validateUpgradeVersions(string $currentVer, string $latestVer) { | ||
| if (!$currentVer) { | ||
| throw new CRM_Core_Exception(ts('Version information missing in civicrm database.')); | ||
| } | ||
| elseif (stripos($currentVer, 'upgrade')) { | ||
| throw new CRM_Core_Exception(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.')); | ||
| } | ||
| if (!$latestVer) { | ||
| throw new CRM_Core_Exception(ts('Version information missing in civicrm codebase.')); | ||
| } |
There was a problem hiding this comment.
[LOW | PROVEN] validateUpgradeVersions(string $currentVer) turns the 'Version information missing' error into a TypeError
CRM_Core_BAO_Domain::version(TRUE) returns whatever singleValueQuery() returns, which is NULL when there is no version. CRM_Upgrade_Form::getUpgradeVersions() passes that value straight into validateUpgradeVersions(string $currentVer, string $latestVer). PHP throws a TypeError for a NULL argument to a non-nullable string parameter, so the friendly if (!$currentVer) CRM_Core_Exception can never be reached for NULL. Before this PR, the inline code handled NULL correctly.
Suggested fix: Make the parameters nullable or untyped, so the existing falsy checks still run and throw CRM_Core_Exception.
| public static function validateUpgradeVersions(string $currentVer, string $latestVer) { | |
| if (!$currentVer) { | |
| throw new CRM_Core_Exception(ts('Version information missing in civicrm database.')); | |
| } | |
| elseif (stripos($currentVer, 'upgrade')) { | |
| throw new CRM_Core_Exception(ts('Database check failed - the database looks to have been partially upgraded. You may want to reload the database with the backup and try the upgrade process again.')); | |
| } | |
| if (!$latestVer) { | |
| throw new CRM_Core_Exception(ts('Version information missing in civicrm codebase.')); | |
| } | |
| public static function validateUpgradeVersions(?string $currentVer, ?string $latestVer) { |
Evidence (95%, `correctness`)
Failure scenario: A database whose civicrm_domain.version is NULL or whose domain row is missing runs the web upgrader or cv updb. The user should see 'Version information missing in civicrm database.' Instead they get an uncaught TypeError: ... Argument #1 ($currentVer) must be of type string, null given.
Verification evidence: I read Versions.php:95-105 and Domain.php:88-103 at head. A live probe on stack B passed a NULL from singleValueQuery and got a TypeError instead of a CRM_Core_Exception. Severity is lowered to low because a NULL domain version is a rare, already-broken database state. Only the error message gets worse.
Proof command: cv ev "try { \CRM_Upgrade_Versions::validateUpgradeVersions(CRM_Core_DAO::singleValueQuery('SELECT NULL'), '6.22.alpha1'); } catch (\Throwable $e) { echo get_class($e) . ': ' . $e->getMessage(); }" (target B)
TypeError: CRM_Upgrade_Versions::validateUpgradeVersions(): Argument #1 ($currentVer) must be of type string, null given
References: civicrm-core/CRM/Core/BAO/Domain.php:88
| $latestVersion = exec("cv ev --level=classloader 'echo \CRM_Upgrade_Versions::getLatestVersion();'"); | ||
| if (version_compare($newVersion, $latestVersion, '<')) { | ||
| fatal("db upgrade steps are declared up to {$latestVersion} - cannot set release version lower than this!"); | ||
| } |
There was a problem hiding this comment.
[LOW | PROVEN] set-version.php upgrade-step guard silently passes if cv is missing or fails
exec("cv ev --level=classloader ...") returns an empty string when cv is not installed, cannot find the checkout or errors out, because errors go to stderr. version_compare($newVersion, '', '<') is FALSE, so the check passes without any message. The exit code and output format are not checked. This check replaces the removed runtime 'Malformed upgrade sequence' guard, so failing open removes the only remaining protection. It also runs after syncPackagesBranch() (line 43), so any failure would come after that step has already run.
Suggested fix: Capture the return code and validate the output, then fail hard. Move the check above syncPackagesBranch().
| $latestVersion = exec("cv ev --level=classloader 'echo \CRM_Upgrade_Versions::getLatestVersion();'"); | |
| if (version_compare($newVersion, $latestVersion, '<')) { | |
| fatal("db upgrade steps are declared up to {$latestVersion} - cannot set release version lower than this!"); | |
| } | |
| $latestVersion = exec("cv ev --level=classloader 'echo \\CRM_Upgrade_Versions::getLatestVersion();'", $out, $rc); | |
| if ($rc !== 0 || !isVersionValid($latestVersion)) { | |
| fatal("unable to determine latest declared upgrade version via cv"); | |
| } |
Evidence (90%, `correctness`)
Failure scenario: The release script runs set-version.php somewhere without a working cv (for example a bare checkout, as colemanw and seamuslee001 described). A release is tagged with a version below the highest declared upgrade step and no error appears. Sites then upgrade to a DB version above the code version.
Verification evidence: I read set-version.php:40-50 at head. A live probe on B showed that exec() of a failing command returns an empty string, and that version_compare('6.22.0', '', '<') is FALSE. I did not verify whether the releaser environment has a working cv.
Proof command: php -r "$v = exec('cv-does-not-exist ev x 2>/dev/null'); var_dump($v, version_compare('6.22.0', $v, '<'));" (target B)
string(0) ""
bool(false)
|
|
||
| // Are there outstanding core version upgrades? | ||
| $upgradeFinished = !CRM_Core_BAO_Domain::isDBUpdateRequired(); | ||
| $upgradeFinished = !\CRM_Upgrade_Versions::upgradesPending(); |
There was a problem hiding this comment.
[LOW | CONFIRMED] Other 'upgrade pending' checks still compare the DB version to the XML version only
Only DispatchPolicy::pick() moved to CRM_Upgrade_Versions::upgradesPending(). These still compare against CRM_Utils_System::version(): CRM_Core_BAO_Domain::isDBUpdateRequired() (used by Env.php:830/916, Schema.php:97 and civiimport.php:87) and Civi\Schema\EntityProvider::getSupportedFields(). When pre-release steps are pending and the DB version equals the XML version, these report no upgrade needed and do not hide fields that have not been added yet.
Suggested fix: Have isDBUpdateRequired() delegate to CRM_Upgrade_Versions::upgradesPending(), or state explicitly that this is out of scope for dev sites.
Evidence (80%, `correctness`)
Failure scenario: A dev site's DB version equals the XML version, and an unapplied pre-release step exists above it. The 'database upgrade required' status check never appears, so the site owner is not told to run the upgrade. Behaviour now differs between the upgrader and the status checks.
Verification evidence: I read Domain.php:112-116 at head and EntityProvider.php:69-83. civicrm_grep lists the remaining callers. This only affects dev sites that have pre-release steps (the PR body says so), which is why severity is low. I did not run it, because the stack has no step above the XML version.
References: civicrm-core/CRM/Core/BAO/Domain.php:112, civicrm-core/Civi/Schema/EntityProvider.php:71, civicrm-core/CRM/Utils/Check/Component/Env.php:916
Overview
Allows running upgrade steps pre-release, without having to wrangle with
set-version.phpShouldn't make any difference with released code.
Technical Details
This should only ever happen on dev sites. Maybe a guard around debug mode or similar would be appropriate?
There's some edginess in that
cv updbchecksCRM_Utils_System::versiondirectly, so won't start the upgrade unless there is a discrepancy between xml version and db version.I think this decoupling is a small step in the direction of
namedmigration steps rather than version-number-tied ones.